import * as types from '../constants/ActionTypes';

export default function domessage(state = [], action = {}) {
    const {
        type, payload
    } = action;

    switch (type) {  
        case types.FETCH_MESSAGE_COUNT:
            return { ...payload };
        case types.FETCH_MESSAGE_COUNT_SUCCESS:

            if (payload.results && payload.results.length) {
                return {
                    count: payload.results[0].num,
                    message_count_status : 1,
                    message : "获取消息数量成功"
                };
            }
            return { ...state };

        case types.FETCH_MESSAGE_COUNT_FAILURE:
            return {
                message_count_status : -1,
                message : "获取消息数量失败",
                count : state.count
            };
        case types.RESET_MESSAGE_COUNT:
            let result = {
                reset_message_count_status : -1,
                message : "清除消息数量成功",
                count : 0
            };
            return {...state, ...result};
        default:
            return state;
    }
}